package net.sxnic.item.action;

import java.util.List;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.dao.hibernate3.HibernateDaoUtils;
import net.sxinfo.core.dao.hibernate3.HibernateOrder;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.comm.utils.PropertyUtil;
import net.sxnic.item.ItemConstants;
import net.sxnic.item.mdata.action.MdataAction;
import net.sxnic.item.zzdw.ZzdwManager;
import net.sxnic.jhitem.itemoperation.ItemOperation;
import net.sxnic.normal.util.Constants;
import net.sxnic.ugr.context.AppContext;
import net.sxnic.ugr.role.Role;
import net.sxnic.ugr.user.User;
import net.sxnic.workflow.task.Task;
import net.sxnic.workflow.task.TaskManager;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 厅领导的项目列表
 * @author 舒强
 *
 */
@SuppressWarnings("serial")
public class ItemList extends MdataAction {

	private static String PASSSTATUS = "0400";
	private Page datas;
	
	@Autowired
	private ZzdwManager zzdwManager;

	private String txtName;
	
	private String zzdw;
	
	private String soperCode;
	
	// zzdw gldw gzdw
	private String deptCate;
		
	public String execute() throws Exception {
		//年份处理，若属性表中未定义，则读取当前年
		String currentYear = PropertyUtil.getProperty("item.currentyear");
		if(StringUtils.isBlank(currentYear)) {
			currentYear = ItemConstants.APP_YEAR;
		}
		//操作年，只有操作年=申报书里的年份，才能提交修改，否则只能查看
		request.setAttribute("optYear", this.getJhYear(currentYear));
		
		if(StringUtils.isBlank(appYear)){
			appYear= currentYear;
		}
		catalogAlias = ItemConstants.SYSTEM_CALALOG_ALIAS;
		
		//组织单位、管理单位、工作单位 角色才能进入此action
		
		int pageNumber = WebUtils.getPageNumber(request);
		int pageSize = WebUtils.getPageSize(request);
		
		//设置排序（默认ID）
		HibernateOrder infoOrder = HibernateDaoUtils.createHibernateOrder(
				"soperCode", true);
		//设置查询条件
		HibernateCriteria hc = new HibernateCriteria().add(infoOrder);
		Criterion dc = null;
		dc = Restrictions.eq("statusOrder", PASSSTATUS);
		hc.add(dc);
		if(StringUtils.isNotBlank(appYear)){
			dc = Restrictions.eq("appYear", this.getJhYear(appYear));		
			hc.add(dc);
		}
		
		if(StringUtils.isNotBlank(catalogAlias)){
			dc = Restrictions.eq("catalog1", catalogAlias);
			hc.add(dc);
		}
		
		if(StringUtils.isNotBlank(zzdw)){
			dc = Restrictions.eq("zzdwCode", zzdw);
			hc.add(dc);
		}
		
		if(StringUtils.isNotBlank(soperCode)){
			dc = Restrictions.eq("soperCode", soperCode);
			hc.add(dc);
		}
		
		if(StringUtils.isNotBlank(txtName)){
			dc = Restrictions.like("appName", "%"+txtName+"%");
			hc.add(dc);
		}
		
		datas = mdManager.getPageByCriteria(pageNumber, pageSize, hc);				

		return SUCCESS;
	}
	
	public Page getDatas() {
		return datas;
	}

	public void setDatas(Page datas) {
		this.datas = datas;
	}

	public String getTxtName() {
		return txtName;
	}

	public void setTxtName(String txtName) {
		this.txtName = txtName;
	}

	public String getZzdw() {
		return zzdw;
	}

	public void setZzdw(String zzdw) {
		this.zzdw = zzdw;
	}

	public String getDeptCate() {
		return deptCate;
	}

	public void setDeptCate(String deptCate) {
		this.deptCate = deptCate;
	}

	public String getSoperCode() {
		return soperCode;
	}

	public void setSoperCode(String soperCode) {
		this.soperCode = soperCode;
	}
}
